package com.sinosoft.zyxt.task;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimerTask;

import org.springframework.transaction.annotation.Transactional;

import com.sinosoft.cnmuseum.dao.MbGyFileDao;
import com.sinosoft.cnmuseum.dao.MbManageAudiofrequencyDao;
import com.sinosoft.cnmuseum.dao.MbManageImageDao;
import com.sinosoft.cnmuseum.dao.MbManageVideoDao;
import com.sinosoft.cnmuseum.dao.MbMusicDbrwDao;
import com.sinosoft.cnmuseum.dao.MbMusicWhrlxxxDao;
import com.sinosoft.cnmuseum.dao.MbMusicWhsxDao;
import com.sinosoft.cnmuseum.dao.MbMusicXzxxDao;
import com.sinosoft.cnmuseum.dao.MbMusicYxxxDao;
import com.sinosoft.cnmuseum.dao.MbsjjsDao;
import com.sinosoft.cnmuseum.entity.MbGyFile;
import com.sinosoft.cnmuseum.entity.MbManageAudiofrequency;
import com.sinosoft.cnmuseum.entity.MbManageImage;
import com.sinosoft.cnmuseum.entity.MbManageVideo;
import com.sinosoft.cnmuseum.entity.MbMusicDbrw;
import com.sinosoft.cnmuseum.entity.MbMusicWhsx;
import com.sinosoft.cnmuseum.utils.LogUtils;
import com.sinosoft.commontools.date.DateHelp;
import com.sinosoft.commontools.record.Record;
import com.sinosoft.commontools.str.StrHelp;
import com.sinosoft.zyxt.jdbc.JdbcUtil;

public class MbimgTimerTask extends TimerTask {

	public static final String SOURCE = "民族博物馆乐器数据库系统";
	public static final int SPARTID = 1;
	public static final int audio = 1;
	public static final int video = 2;
	public static final int image = 3;

	@Override
	public void run() {
		// TODO Auto-generated method stub
		// 获取知识库的相关数据 将数据传输到资源数据库 将待传输文件存入list集合中
		getMbfileInfo();
		//

	}

	@Transactional
	private void getMbfileInfo() {
			
		try {
			
			MbsjjsDao sjjsDao = new MbsjjsDao();
			String sql = " select * from mb_music_sjjs";// where id=72379
			//String sql = " select * from mb_music_sjjs where";// where id=72379
			List<Record> bySql = sjjsDao.getBySql(sql);

			for (Record record : bySql) {
				if(record!=null){
				String collectionCode = record.getStrValue("collection_code");// 获取藏品编号
				Integer gcxxid = record.getIntValue("id");
			
				String faithimage = record.getStrValue("faithimage");
				System.out.println("WWWWWWWWWWWWWW"+faithimage);
				String faithaudio = record.getStrValue("faithaudio");
				String faithvideo = record.getStrValue("faithvideo");
				if (faithimage != null && faithimage.length()>0) {
					Record fileInfo = getimageFileInfo(faithimage);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageImage = (Record) fileInfo.getValue("manageImage");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageImage.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveImageInfoToMbzy(record, manageImage, gyfile);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (faithaudio != null && faithaudio.length()>0) {
					Record fileInfo = getaudioFileInfo(faithaudio);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageAudio = (Record) fileInfo.getValue("manageAudio");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageAudio.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageAudio, gyfile,
									audio);

						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);
						}
					}
				}
				if (faithvideo != null && faithvideo.length()>0) {
					Record fileInfo = getvideoFileInfo(faithvideo);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageVideo = (Record) fileInfo.getValue("manageVideo");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageVideo.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageVideo, gyfile,
									video);

						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);
						}
					}
				}

				MbMusicXzxxDao xzxxDao = new MbMusicXzxxDao();
				Record dataByGcxxid = xzxxDao.getDataByGcxxid(gcxxid);
				if(dataByGcxxid!=null) {
				String formdrawing = dataByGcxxid.getStrValue("formDrawing");
				String formdescription = dataByGcxxid.getStrValue("formDescription");
				String improvestateimage = dataByGcxxid.getStrValue("improveStateImage");

				if (formdrawing != null && formdrawing.length()>0) {
					Record fileInfo = getimageFileInfo(formdrawing);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageImage = (Record) fileInfo.getValue("manageImage");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageImage.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveImageInfoToMbzy(record, manageImage, gyfile);

						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);
						}
					}
				}
//				if (formdescription != "" && formdescription != null) {
//					Record fileInfo = getvideoFileInfo(formdescription);
//					if (!fileInfo.getBoolValue("isTransmission")) {
//						boolean saveImageInfoToMbzy = true;
//						Record manageVideo = (Record) fileInfo.getValue("manageVideo");
//						Record gyfile = (Record) fileInfo.getValue("gyfile");
//						if (manageVideo.getIntValue("isSource") == 0) {
//							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageVideo, gyfile,
//									video);
//
//						}
//						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
//							createFile(gyfile);
//						}
//					}
//				}
				if (improvestateimage != null && improvestateimage.length()>0) {
					Record fileInfo = getimageFileInfo(improvestateimage);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageImage = (Record) fileInfo.getValue("manageImage");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageImage.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveImageInfoToMbzy(record, manageImage, gyfile);

						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);
						}
						
					}
				}
			}
				MbMusicWhrlxxxDao whrlxxxDao = new MbMusicWhrlxxxDao();
				Record dataByGcxxid2 = whrlxxxDao.getDataByGcxxid(gcxxid);
				if(dataByGcxxid2!=null) {
				String originimage = dataByGcxxid2.getStrValue("originImage");
				String originaudio = dataByGcxxid2.getStrValue("originAudio");
				String originvideo = dataByGcxxid2.getStrValue("originVideo");
				String historyimage = dataByGcxxid2.getStrValue("historyImage");
				String historyaudio = dataByGcxxid2.getStrValue("historyAudio");
				String historyvideo = dataByGcxxid2.getStrValue("historyVideo");
				String folkloreimage = dataByGcxxid2.getStrValue("folkloreImage");
				String folkloreaudio = dataByGcxxid2.getStrValue("folkloreAudio");
				String folklorevideo = dataByGcxxid2.getStrValue("folkloreVideo");
				String faithimageGcxx = dataByGcxxid2.getStrValue("faithImage");
				String faithaudioGcxx = dataByGcxxid2.getStrValue("faithAudio");
				String faithvideoGcxx = dataByGcxxid2.getStrValue("faithVideo");

				if (originimage != null && originimage.length()>0) {
					Record fileInfo = getimageFileInfo(originimage);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageImage = (Record) fileInfo.getValue("manageImage");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageImage.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveImageInfoToMbzy(record, manageImage, gyfile);

						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);
						}
					}
				}
				if (originaudio != null && originaudio.length()>0) {
					Record fileInfo = getaudioFileInfo(originaudio);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageAudio = (Record) fileInfo.getValue("manageAudio");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageAudio.getIntValue("isSource") == 0) {
							 saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageAudio, gyfile,
									audio);

						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);
						}
					}
				}
				if (originvideo != null && originvideo.length()>0) {
					Record fileInfo = getvideoFileInfo(originvideo);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageVideo = (Record) fileInfo.getValue("manageVideo");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageVideo.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageVideo, gyfile,
									video);

						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (historyimage != null && historyimage.length()>0) {
					Record fileInfo = getimageFileInfo(historyimage);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageImage = (Record) fileInfo.getValue("manageImage");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageImage.getIntValue("isSource") == 0) {
							 saveImageInfoToMbzy = saveImageInfoToMbzy(record, manageImage, gyfile);

						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (historyaudio != null && historyaudio.length()>0) {
					Record fileInfo = getaudioFileInfo(historyaudio);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageAudio = (Record) fileInfo.getValue("manageAudio");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageAudio.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageAudio, gyfile, audio);

						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (historyvideo != null && historyvideo.length()>0) {
					Record fileInfo = getvideoFileInfo(historyvideo);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageVideo = (Record) fileInfo.getValue("manageVideo");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageVideo.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageVideo, gyfile, video);

						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (folkloreimage != null && folkloreimage.length()>0) {
					Record fileInfo = getimageFileInfo(folkloreimage);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageImage = (Record) fileInfo.getValue("manageImage");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageImage.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveImageInfoToMbzy(record, manageImage, gyfile);

						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (folkloreaudio != null && folkloreaudio.length()>0) {
					Record fileInfo = getaudioFileInfo(folkloreaudio);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageAudio = (Record) fileInfo.getValue("manageAudio");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageAudio.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageAudio, gyfile, video);

						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (folklorevideo != null && folklorevideo.length()>0) {
					Record fileInfo = getvideoFileInfo(folklorevideo);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageVideo = (Record) fileInfo.getValue("manageVideo");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageVideo.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageVideo, gyfile, video);

						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (faithimageGcxx != null && faithimageGcxx.length()>0) {
					Record fileInfo = getimageFileInfo(faithimageGcxx);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageImage = (Record) fileInfo.getValue("manageImage");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageImage.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveImageInfoToMbzy(record, manageImage, gyfile);

						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (faithaudioGcxx != null && faithaudioGcxx.length()>0) {
					Record fileInfo = getaudioFileInfo(faithaudioGcxx);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageAudio = (Record) fileInfo.getValue("manageAudio");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageAudio.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageAudio, gyfile, audio);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (faithvideoGcxx != null && faithvideoGcxx.length()>0) {
					Record fileInfo = getvideoFileInfo(faithvideoGcxx);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageVideo = (Record) fileInfo.getValue("manageVideo");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageVideo.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageVideo, gyfile, video);

						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
			}
				MbMusicYxxxDao yxxxDao = new MbMusicYxxxDao();
				Record dataByGcxxid3 = yxxxDao.getDataByGcxxid(gcxxid);
				if(dataByGcxxid3!=null) {
				String pitchaudio = dataByGcxxid3.getStrValue("pitchAudio");
				String toneaudio = dataByGcxxid3.getStrValue("toneAudio");
				String temperamentaudio = dataByGcxxid3.getStrValue("temperamentAudio");
				String rangeaudio = dataByGcxxid3.getStrValue("rangeAudio");
				String bestregisteraudio = dataByGcxxid3.getStrValue("bestRegisterAudio");
				String tonemethodaudio = dataByGcxxid3.getStrValue("toneMethodAudio");
				String voicemechanismvideo = dataByGcxxid3.getStrValue("voiceMechanismVideo");
				String provokevideo = dataByGcxxid3.getStrValue("provokeVideo");
				String structimage = dataByGcxxid3.getStrValue("structImage");
				String structvideo = dataByGcxxid3.getStrValue("structVideo");
				String mediatormaterialimage = dataByGcxxid3.getStrValue("mediatorMaterialImage");
				String mediatorstructimage = dataByGcxxid3.getStrValue("resonatorStrutImage");
				String mediatorshapeaudio = dataByGcxxid3.getStrValue("mediatorShapeAudio");
				String vibrationtransfermaterialimage = dataByGcxxid3.getStrValue("vibrationTransferMaterialImage");
				String vibrationtransferstructimage = dataByGcxxid3.getStrValue("vibrationTransferStructImage");
				String resonatormaterialimage = dataByGcxxid3.getStrValue("resonatorMaterialImage");
				String resonatorstrutimage = dataByGcxxid3.getStrValue("resonatorStrutImage");
				String mainpartsoundaudio = dataByGcxxid3.getStrValue("mainPartSoundAudio");
				String techniquesvideo = dataByGcxxid3.getStrValue("techniquesVideo");
				String spectrumimage = dataByGcxxid3.getStrValue("spectrumImage");
				String spectrumanalysisimage = dataByGcxxid3.getStrValue("spectrumAnalysisImage");

				if (pitchaudio != null && pitchaudio.length()>0) {
					Record fileInfo = getaudioFileInfo(pitchaudio);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageAudio = (Record) fileInfo.getValue("manageAudio");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageAudio.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageAudio, gyfile, audio);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (toneaudio != null && toneaudio.length()>0) {
					Record fileInfo = getaudioFileInfo(toneaudio);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageAudio = (Record) fileInfo.getValue("manageAudio");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageAudio.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageAudio, gyfile, audio);

						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (temperamentaudio != null && temperamentaudio.length()>0) {
					Record fileInfo = getaudioFileInfo(temperamentaudio);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageAudio = (Record) fileInfo.getValue("manageAudio");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageAudio.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageAudio, gyfile, audio);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (rangeaudio != null && rangeaudio.length()>0) {
					Record fileInfo = getaudioFileInfo(rangeaudio);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageAudio = (Record) fileInfo.getValue("manageAudio");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageAudio.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageAudio, gyfile, audio);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (bestregisteraudio != null && bestregisteraudio.length()>0) {
					Record fileInfo = getaudioFileInfo(bestregisteraudio);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageAudio = (Record) fileInfo.getValue("manageAudio");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageAudio.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageAudio, gyfile, audio);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (tonemethodaudio != null && tonemethodaudio.length()>0) {
					Record fileInfo = getaudioFileInfo(tonemethodaudio);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageAudio = (Record) fileInfo.getValue("manageAudio");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageAudio.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageAudio, gyfile, audio);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (voicemechanismvideo != null && voicemechanismvideo.length()>0) {
					Record fileInfo = getvideoFileInfo(voicemechanismvideo);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageVideo = (Record) fileInfo.getValue("manageVideo");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageVideo.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageVideo, gyfile, video);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (provokevideo != null && provokevideo.length()>0) {
					Record fileInfo = getvideoFileInfo(provokevideo);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageVideo = (Record) fileInfo.getValue("manageVideo");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageVideo.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageVideo, gyfile, video);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (structimage != null && structimage.length()>0) {
					Record fileInfo = getimageFileInfo(structimage);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageImage = (Record) fileInfo.getValue("manageImage");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageImage.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveImageInfoToMbzy(record, manageImage, gyfile);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (structvideo != null && structvideo.length()>0) {
					Record fileInfo = getvideoFileInfo(structvideo);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageVideo = (Record) fileInfo.getValue("manageVideo");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageVideo.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageVideo, gyfile, video);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (mediatormaterialimage != null && mediatormaterialimage.length()>0) {
					Record fileInfo = getimageFileInfo(mediatormaterialimage);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageImage = (Record) fileInfo.getValue("manageImage");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageImage.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveImageInfoToMbzy(record, manageImage, gyfile);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (mediatorstructimage != null && mediatorstructimage.length()>0) {
					Record fileInfo = getimageFileInfo(mediatorstructimage);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageImage = (Record) fileInfo.getValue("manageImage");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageImage.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveImageInfoToMbzy(record, manageImage, gyfile);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (mediatorshapeaudio != null && mediatorshapeaudio.length()>0) {
					Record fileInfo = getaudioFileInfo(mediatorshapeaudio);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageAudio = (Record) fileInfo.getValue("manageAudio");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageAudio.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageAudio, gyfile, audio);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (vibrationtransfermaterialimage != null && vibrationtransfermaterialimage.length()>0) {
					Record fileInfo = getimageFileInfo(vibrationtransfermaterialimage);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageImage = (Record) fileInfo.getValue("manageImage");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageImage.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveImageInfoToMbzy(record, manageImage, gyfile);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (vibrationtransferstructimage != null && vibrationtransferstructimage.length()>0) {
					Record fileInfo = getimageFileInfo(vibrationtransferstructimage);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageImage = (Record) fileInfo.getValue("manageImage");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageImage.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveImageInfoToMbzy(record, manageImage, gyfile);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (resonatormaterialimage != null && resonatormaterialimage.length()>0) {
					Record fileInfo = getimageFileInfo(resonatormaterialimage);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageImage = (Record) fileInfo.getValue("manageImage");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageImage.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveImageInfoToMbzy(record, manageImage, gyfile);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (resonatorstrutimage != null && resonatorstrutimage.length()>0) {
					Record fileInfo = getimageFileInfo(resonatorstrutimage);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageImage = (Record) fileInfo.getValue("manageImage");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageImage.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveImageInfoToMbzy(record, manageImage, gyfile);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (mainpartsoundaudio != null && mainpartsoundaudio.length()>0) {
					Record fileInfo = getaudioFileInfo(mainpartsoundaudio);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageAudio = (Record) fileInfo.getValue("manageAudio");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageAudio.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageAudio, gyfile, audio);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (techniquesvideo != null && techniquesvideo.length()>0) {
					Record fileInfo = getvideoFileInfo(techniquesvideo);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageVideo = (Record) fileInfo.getValue("manageVideo");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageVideo.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageVideo, gyfile, video);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (spectrumimage != null && spectrumimage.length()>0) {
					Record fileInfo = getimageFileInfo(spectrumimage);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageImage = (Record) fileInfo.getValue("manageImage");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageImage.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveImageInfoToMbzy(record, manageImage, gyfile);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (spectrumanalysisimage != null && spectrumanalysisimage.length()>0) {
					Record fileInfo = getimageFileInfo(spectrumanalysisimage);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageImage = (Record) fileInfo.getValue("manageImage");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageImage.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveImageInfoToMbzy(record, manageImage, gyfile);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				}
				MbMusicWhsxDao whsxDao = new MbMusicWhsxDao();
				Record dataByGcxxid4 = whsxDao.getDatazByGcxxid(gcxxid);
				if(dataByGcxxid4!=null) {
				String musicscoreimage = dataByGcxxid4.getStrValue("musicScoreImage");
				String inheritteachvideo = dataByGcxxid4.getStrValue("inheritTeachVideo");

				if (musicscoreimage != null && musicscoreimage.length()>0) {

					Record fileInfo = getimageFileInfo(musicscoreimage);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageImage = (Record) fileInfo.getValue("manageImage");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageImage.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveImageInfoToMbzy(record, manageImage, gyfile);
						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);

						}
					}
				}
				if (inheritteachvideo != null && inheritteachvideo.length()>0) {
					Record fileInfo = getvideoFileInfo(inheritteachvideo);
					if (!fileInfo.getBoolValue("isTransmission")) {
						boolean saveImageInfoToMbzy = true;
						Record manageVideo = (Record) fileInfo.getValue("manageVideo");
						Record gyfile = (Record) fileInfo.getValue("gyfile");
						if (manageVideo.getIntValue("isSource") == 0) {
							saveImageInfoToMbzy = saveAudioVideoInfoToMbzy(record, manageVideo, gyfile, video);

						}
						if (gyfile.getIntValue("isSave") == 0 && saveImageInfoToMbzy) {
							createFile(gyfile);
						}
					}
				}
				}
				}
			}
			
			LogUtils log = new LogUtils();
			log.addLog(String.valueOf(LogUtils.type_submit), LogUtils.model_sjcs, null, "本系统传输文件致资源系统完毕");
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}

	}

	private Record getimageFileInfo(String ID) {
		LogUtils log = new LogUtils();
		try {
			Record file = new Record();

			MbManageImageDao imageDao = new MbManageImageDao();

			String sqlM = "select * from {0} as file left join mb_gy_sxcjgs as fileT on file.fileFormat = fileT.id    left join mb_gy_file as fileG on fileG.id = file.fileid where  file.zdbh = {1} ";
			String formatM = MessageFormat.format(sqlM, MbManageImage.MB_MANAGE_IMAGE_TABLE_NAME, ID);
			List<Record> bySqlM = imageDao.getBySql(formatM);
			if (bySqlM.size() == 0) {
				file.add("isTransmission", true);
			}
			String fileid = "";
			for (Record record : bySqlM) {
				fileid = record.getStrValue("fileid");
				file.add("manageImage", record);
			}

			MbGyFileDao fileDao = new MbGyFileDao();
			String sql = "select * from {0} where id = {1}";
			String format = MessageFormat.format(sql, MbGyFile.MB_GY_FILE_TABLE_NAME, "'" + fileid + "'");
			List<Record> bySql = fileDao.getBySql(format);

			for (Record record : bySql) {
				file.add("gyfile", record);
			}
			file.add("isTransmission", false);
			return file;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			Record file = new Record();
			file.add("isTransmission", true);
			log.addLog(String.valueOf(LogUtils.type_select), LogUtils.model_sjcs, null, "获取本系统-图片文件-数据错误，文件资源ID："+ID);
			return  file;
		}
	}

	private Record getvideoFileInfo(String ID) {
		LogUtils log = new LogUtils();
		try {
			Record file = new Record();

			MbManageImageDao imageDao = new MbManageImageDao();
			String sqlM = "select * from {0} as file    left join mb_gy_file as fileG on fileG.id = file.fileid where  file.zdbh = {1} ";
			String formatM = MessageFormat.format(sqlM, MbManageVideo.MB_MANAGE_VIDEO_TABLE_NAME, ID);
			List<Record> bySqlM = imageDao.getBySql(formatM);
			if (bySqlM.size() == 0) {
				file.add("isTransmission", true);
			}
			String fileid = "";
			for (Record record : bySqlM) {
				fileid = record.getStrValue("fileid");
				file.add("manageVideo", record);
			}

			MbGyFileDao fileDao = new MbGyFileDao();
			String sql = "select * from {0} where id = {1}";
			String format = MessageFormat.format(sql, MbGyFile.MB_GY_FILE_TABLE_NAME, "'" + fileid + "'");
			List<Record> bySql = fileDao.getBySql(format);

			for (Record record : bySql) {
				file.add("gyfile", record);
			}
			file.add("isTransmission", false);
			return file;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			Record file = new Record();
			file.add("isTransmission", true);
			log.addLog(String.valueOf(LogUtils.type_select), LogUtils.model_sjcs, null, "获取本系统-视频文件-数据错误，文件资源ID："+ID);
			return  file;
		}
	}

	private Record getaudioFileInfo(String ID) {
		LogUtils log = new LogUtils();
		try {
			Record file = new Record();

			MbManageImageDao imageDao = new MbManageImageDao();
			String sqlM = "select * from {0} as file    left join mb_gy_file as fileG on fileG.id = file.fileid where  file.zdbh = {1} ";
			String formatM = MessageFormat.format(sqlM, MbManageAudiofrequency.MB_MANAGE_AUDIOFREQUENCY_TABLE_NAME, ID);
			List<Record> bySqlM = imageDao.getBySql(formatM);
			if (bySqlM.size() == 0) {
				file.add("isTransmission", true);
			}
			String fileid = "";
			for (Record record : bySqlM) {
				fileid = record.getStrValue("fileid");
				file.add("manageAudio", record);
			}

			MbGyFileDao fileDao = new MbGyFileDao();
			String sql = "select * from {0} where id = {1}";
			String format = MessageFormat.format(sql, MbGyFile.MB_GY_FILE_TABLE_NAME, "'" + fileid + "'");
			List<Record> bySql = fileDao.getBySql(format);

			for (Record record : bySql) {
				file.add("gyfile", record);
			}
			file.add("isTransmission", false);
			return file;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			Record file = new Record();
			file.add("isTransmission", true);
			log.addLog(String.valueOf(LogUtils.type_select), LogUtils.model_sjcs, null, "获取本系统-音频文件-数据错误，文件资源ID："+ID);
			return  file;
		}
	
	}
	@Transactional
	private boolean saveImageInfoToMbzy(Record gcxx, Record manage, Record gyFile) throws SQLException {
		Connection connection = null;
		PreparedStatement prepareStatement = null;
		PreparedStatement prepareStatement2 = null;
		LogUtils log = new LogUtils();
		try {
			connection = JdbcUtil.getConnection();
			connection.setAutoCommit(false);// 关闭自动提交
			String insertSql = "INSERT INTO  m_image(internal_id,imgname,imgtype,imgsource,shotdate,equipment,imgresolution,imgwidth,imgheight,imgext,imgsize,relicnum,relicname,relictype,Inputoper,inputdate,auditoper,auditdate,national,mw_national,keywords,rawext,spart_id)  VALUES(SEQ_M_IMAGE.nextval,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

			prepareStatement = connection.prepareStatement(insertSql);
			prepareStatement.setString(1, manage.getStrValue("title"));// 图片名称
			prepareStatement.setInt(2, 0);// 图片类别
			prepareStatement.setString(3, SOURCE);// 图片来源
			prepareStatement.setString(4, manage.getStrValue("created"));// 拍摄时间
			prepareStatement.setString(5, "");// 拍摄地点
			prepareStatement.setString(6, "");// 图片分辨率
			prepareStatement.setString(7, manage.getStrValue("extent_w"));// 图片宽度
			prepareStatement.setString(8, manage.getStrValue("extent_h"));// 图片高度
			prepareStatement.setString(9, manage.getStrValue("name"));// 文件格式
			prepareStatement.setString(10, manage.getStrValue("size"));// 文件大小
			prepareStatement.setString(11, gcxx.getStrValue("collection_code"));// 藏品编号
			prepareStatement.setString(12, gcxx.getStrValue("title"));// 藏品名称
			prepareStatement.setString(13, "");// 藏品分类
			prepareStatement.setString(14, "");// 录入人员
			prepareStatement.setString(15, "");// 录入时间
			prepareStatement.setString(16, "");// 审核人员
			prepareStatement.setString(17, "");// 审核时间
			prepareStatement.setString(18, gcxx.getStrValue("useNation"));// 民族
			prepareStatement.setString(19, gcxx.getStrValue("useNation_text"));// 民族
			
			prepareStatement.setString(20, gcxx.getStrValue("gjz"));// 关键词
			prepareStatement.setString(21, gyFile.getStrValue("filename"));// 原始文件名
			prepareStatement.setInt(22, SPARTID);// 存储区编号
			System.out.println(prepareStatement.toString());
			int i = prepareStatement.executeUpdate();

			// 存 图片文件imagefile
			String insertSql2 = "insert  into IMAGEFILE(internal_id,filename_pre,ext,filesize,rawext,spart_id,sub_path,imgresolution,imgwidth,imgheight,memodesc) VALUES(SEQ_IMAGEFILE.nextval,?,?,?,?,?,?,?,?,?,?)";
			prepareStatement2 = connection.prepareStatement(insertSql2);
			prepareStatement2.setString(1, manage.getStrValue("title"));// 资源名称
			prepareStatement2.setString(2, manage.getStrValue("name"));// 文件类型
			prepareStatement2.setString(3, manage.getStrValue("size"));// 文件大小
			prepareStatement2.setString(4, gyFile.getStrValue("filename"));// 原始文件名
			prepareStatement2.setInt(5, SPARTID);// 存储区编号

			Calendar now = Calendar.getInstance();
			int y = now.get(Calendar.YEAR);
			int m = now.get(Calendar.MONTH);
			String savePath = String.valueOf(y) + File.separator + String.valueOf(m) + File.separator
					+ String.valueOf(SPARTID) + File.separator + "source" + File.separator;

			prepareStatement2.setString(6, savePath);// 相对路径
			prepareStatement2.setString(7, "");// 图片分辨率
			prepareStatement2.setString(8, manage.getStrValue("extent_w"));// 图片宽度
			prepareStatement2.setString(9, manage.getStrValue("extent_h"));// 图片高度
			prepareStatement2.setString(10, manage.getStrValue("description"));// 图片描述
			int k = prepareStatement2.executeUpdate();

			connection.commit();

			MbManageImageDao audio = new MbManageImageDao();
			Record audioById = audio.getById(manage.getIntValue("zdbh"));
			audioById.add(MbManageAudiofrequency.ISSOURCE, 1);
			audio.update(audioById);

			return true;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			connection.rollback();
			log.addLog(String.valueOf(LogUtils.type_insert), LogUtils.model_sjcs, null, "本系统传输-图片文件数据-致资源系统错误，文件资源ID："+manage.getStrValue("id"));
			return false;
		} finally {
			connection.close();
			prepareStatement.close();
			prepareStatement2.close();
			
		}
	}

	@Transactional
	public void setIsSave(String ID, Integer data) {
		try {
			MbGyFileDao file = new MbGyFileDao();
			Record dataByfileId = file.getDataByfileId(ID);
			dataByfileId.add(MbGyFile.ISSAVE, data);
			file.update(dataByfileId);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
	@Transactional
	private boolean saveAudioVideoInfoToMbzy(Record gcxx, Record manage, Record gyFile, int type)
			throws SQLException {
		Connection connection = null;
		PreparedStatement prepareStatement = null;
		PreparedStatement prepareStatement2 = null;
		LogUtils log = new LogUtils();
		try {
			connection = JdbcUtil.getConnection();
			connection.setAutoCommit(false);// 关闭自动提交
			String insertSql3 = "INSERT INTO m_audiovideo(internal_id,sname,restype,national,slanguage,subject,description,operdate,filetype,filesize,equipment,culturefunc,symbol,legend,relicnum,relicname,relictype,inputoper,inputdate,auditoper,auditdate,filename_pre,ext,fsize,rawext,spart_id,mw_national) VALUES(SEQ_M_AUDIOVIDEO.nextval,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
			prepareStatement2 = connection.prepareStatement(insertSql3);
			prepareStatement2.setString(1, manage.getStrValue("title"));// 名称
			prepareStatement2.setInt(2, 0);// 类型
			prepareStatement2.setString(3, gcxx.getStrValue("useNation"));// 民族
			prepareStatement2.setString(4, manage.getStrValue("audiochannellanguage"));// 语种
			prepareStatement2.setString(5, manage.getStrValue("subject"));// 主题
			prepareStatement2.setString(6, manage.getStrValue("description"));// 内容描述
			prepareStatement2.setString(7, manage.getStrValue("created"));// 拍摄时间
			prepareStatement2.setString(8, manage.getStrValue("name"));// 文件格式
			prepareStatement2.setString(9, manage.getStrValue("size"));// 文件大小
			prepareStatement2.setString(10, manage.getStrValue("equipment"));// 采集设备
			prepareStatement2.setString(11, "");// 文化功能
			prepareStatement2.setString(12, "");// 象征与禁忌
			prepareStatement2.setString(13, "");// 民间传说
			prepareStatement2.setString(14, gcxx.getStrValue("collection_code"));// 藏品编号
			prepareStatement2.setString(15, gcxx.getStrValue("title"));// 藏品名称
			prepareStatement2.setString(16, "");// 藏品分类
			prepareStatement2.setString(17, "");// 录入人员
			prepareStatement2.setString(18, "");// 录入时间
			prepareStatement2.setString(19, "");// 审核人员
			prepareStatement2.setString(20, "");// 审核时间

			prepareStatement2.setString(21, manage.getStrValue("alternative"));// 资源名称
			prepareStatement2.setString(22, manage.getStrValue("name"));// 文件类型
			prepareStatement2.setString(23, manage.getStrValue("size"));// 文件大小
			prepareStatement2.setString(24, gyFile.getStrValue("filename"));// 原文件名
			prepareStatement2.setInt(25, SPARTID);// 存储区编号
			prepareStatement2.setString(26, gcxx.getStrValue("useNation_text"));// 民族
			int k = prepareStatement2.executeUpdate();

			// 存 图片文件audiovideofile
			String insertSql4 = "insert into audiovideofile(internal_id,filename_pre,ext,filesize,rawext,spart_id) VALUES(SEQ_AUDIOVIDEOFILE.nextval,?,?,?,?,?)";
			prepareStatement = connection.prepareStatement(insertSql4);
			prepareStatement.setString(1, manage.getStrValue("title"));// 资源名称
			prepareStatement.setString(2, manage.getStrValue("name"));// 文件类型
			prepareStatement.setString(3, manage.getStrValue("size"));// 文件大小
			prepareStatement.setString(4, gyFile.getStrValue("filename"));// 原始文件名
			prepareStatement.setInt(5, SPARTID);// 存储区编号

			int i = prepareStatement.executeUpdate();

			connection.commit();

			switch (type) {
			case 1:
				MbManageAudiofrequencyDao audio = new MbManageAudiofrequencyDao();
				Record audioById = audio.getById(manage.getIntValue("zdbh"));
				audioById.add(MbManageAudiofrequency.ISSOURCE, 1);
				audio.update(audioById);
				break;
			case 2:
				MbManageVideoDao video = new MbManageVideoDao();
				Record videoById = video.getById(manage.getIntValue("zdbh"));
				videoById.add(MbManageVideo.ISSOURCE, 1);
				video.update(videoById);
				break;
			}

			return true;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			connection.rollback();
			log.addLog(String.valueOf(LogUtils.type_insert), LogUtils.model_sjcs, null, "本系统传输-视音频文件数据-致资源系统错误，文件资源ID："+manage.getStrValue("id"));
			return false;
		} finally {
		
			prepareStatement.close();
			prepareStatement2.close();
			connection.close();
		}

	}

	private void createFile(Record file) {
		LogUtils log = new LogUtils();
		try {
			// 按照规则生成资源系统存储文件名称
			String fileName = file.getStrValue("filename");
			String mbfilePath = file.getStrValue("savePath");
			String nowTime = DateHelp.getNowTime("yyyMMddHHmmssSSS");
			String randomStr = StrHelp.getRandomStr(3);
			String saveFileName = nowTime + randomStr + fileName;

			// 按照规则生成资源系统存储路径 年/月/存储区id/source
			String getpartPath = getpartPath();
			if (getpartPath == null || getpartPath == "") {
				return;
			}
			Calendar now = Calendar.getInstance();
			int y = now.get(Calendar.YEAR);
			int m = now.get(Calendar.MONTH)+1;
			String savePath = getpartPath + File.separator + String.valueOf(y) + File.separator + String.valueOf(m)
					+ File.separator + String.valueOf(SPARTID) + File.separator + "source" + File.separator
					+ saveFileName;

			// 判断民博系统文件路径是否存在
			File mbfile = new File(mbfilePath);
			if (!mbfile.exists()) {
				log.addLog(String.valueOf(LogUtils.type_insert), LogUtils.model_sjcs, null, "本系统文件错误，文件资源ID："+file.getStrValue("id"));
				return;// 返回false
			}

			// 判断生成资源系统存储路径是否存在 无则创建文件夹
			File zyfile = new File(savePath);
			if (!zyfile.exists()) {
				zyfile.getParentFile().mkdirs();
				zyfile.createNewFile();
			}
			// 将文件复制到相应目录
			copyFileUsingFileStreams(mbfile, zyfile);

			MbGyFileDao gyfile = new MbGyFileDao();
			Record dataByfileId = gyfile.getDataByfileId(file.getStrValue("id"));
			dataByfileId.add(MbGyFile.ISSAVE, 1);
			gyfile.update(dataByfileId);

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			log.addLog(String.valueOf(LogUtils.type_insert), LogUtils.model_sjcs, null, "本系统传输文件致资源系统错误，文件资源ID："+file.getStrValue("id"));
			
		}

	}

	// 获取存储区的绝对路径
	private String getpartPath() throws SQLException {
		String path = "";
		Connection connection = JdbcUtil.getConnection();
		PreparedStatement prepareStatement = null;
		ResultSet executeQuery = null;
		LogUtils log = new LogUtils();
		try {
			
			
			String sql = "select * from spart where spart_id=?";
			prepareStatement = connection.prepareStatement(sql);
			prepareStatement.setInt(1, 1);
			executeQuery = prepareStatement.executeQuery();

			while (executeQuery.next()) {
				path = executeQuery.getString("absolute_path");
			}
			JdbcUtil.close(connection, prepareStatement, executeQuery);
			return path;
		} catch (SQLException e) {
			e.printStackTrace();
			log.addLog(String.valueOf(LogUtils.type_select), LogUtils.model_sjcs, null, "获取资源系统文件存储区错误");
			
			return null;
		}finally {
			
			prepareStatement.close();
			executeQuery.close();
			connection.close();
		}
	}

	// 复制文件到指定目录
	private void copyFileUsingFileStreams(File source, File dest) throws IOException {
		InputStream input = null;
		OutputStream output = null;
		try {
			input = new FileInputStream(source);
			output = new FileOutputStream(dest);
			byte[] buf = new byte[1024];
			int bytesRead;
			while ((bytesRead = input.read(buf)) > 0) {
				output.write(buf, 0, bytesRead);
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		} finally {
			input.close();
			output.close();
		}
	}



}
